<?php

/**
 * Backend Routes
 *
 * @author jiang
 */

Route::group(array('prefix' => 'admin'), function() {

    /** login route group **/
    Route::group(array('prefix' => 'login'), function() {
        Route::any('{action}', function($action) {
            if($action == 'index' && Auth::check())
                return Redirect::intended(Config::get('admin.login_success_uri'));
            
            $class = 'Kj\\Admin\\Controller\\LoginController';
            $cObj  = new $class();
            return $cObj->$action();
        });
    });

    /** common route group **/
    Route::group(array('before' => 'auth|auth.acl'), function() {
        Route::any('{controller}/{action}', function($controller = false, $action = false) {
            $controller = $controller ? $controller : Config::get('admin.default_controller');
            $action = $action ? $action : Config::get('admin.default_action');
            
            $class = 'Kj\\Admin\\Controller\\'.ucfirst(strtolower($controller)).'Controller';
            $cObj  = new $class();
            return $cObj->$action();
        });
    });

});